package com.yang.app;

import java.io.IOException;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.FileInputFormat;

public class MaxTemperature {
		public static void main (String [] args)
		{
				if (args.length != 2) {
						System.err.println("Usage: MaxTemperature <input path> <output path>");
						System.exit(-1);
				}
				//Object Job is used to confirm the configuration about how this job is
				//carried out. We can use it to control the running of the whole job.
				//When we run this job on the cluster, we should "jar" all of the codes.
				//Then the Hadoop will help to release the job to the computers in the cluster.
				//You won't need to confirm the JAR's name, just pass a class to the "setJarByClass"function
				//of the Object Job.
				//After the construction of the Object Job, you will get a Instance job.
				//you should confirm the path of the data's input and output.
				//Just call the addInputPath function of FileInputFormat class to define the path of the 
				//data's input. the path of data's input could be a single file, a directory(all of the
				//files in that directory will be judged as input data) .
				//Of course, you can call the addInputpath several times to realize the input of multi-path.
				Job job = new Job();
				job.setJarByClass(MaxTemperature.class);
				job.setJobName("Max Ttemperature");

				FileInputFormat.addInputPath(job, new Path(args[0]));
				FileOutputFormat.setOutputPath(job, new Path(args[1]));
				//the setOutputPath function of the FileOutputFormat class is used to confirm
				//the output path. Note: there can be only one output path different from the multi-path of input.
				//the Reduce function will output data to the output path. the output path must not exist, or the
				//Hadoop will report errors and deny to running the job. 
				//To design like that has some real reasons. One of the reasons is to protect from the data 
				//missing.

				job.setMapperClass(MaxTemperatureMapper.class);
				job.setReducerClass(MaxTemperatureReducer.class);
				//the setMapperClass function and the setReducerClass function is used to confirm the map type
				//and the reduce type
				job.setOutputKeyClass(Text.class);
				job.setOutputValueClass(IntWritable.class);

				System.exit(job.waitForCompletion() ? 0 : 1);
		}
}
